<?php

namespace Home\Controller;

use Think\Controller;

class PostController extends  Controller
{
    /**列表
         *
         */
    public  function  lists()
     {
        $model=M("AuthRule");
        $result=$model->query("desc urpi_auth_rule ");
        $arr2 = array_column($result, 'field'); //表头元素
        $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $pagesize = 10;#每页数量
        $count = $model->count();
        $list = $model->order('id desc')->page($p.',10')->select();
        $page = $this->pageShow($count, $pagesize);
        $this->assign('header',$arr2);
        $this->assign('page',$page);
        $this->assign('list',$list);
        $this->display();
    }
    public  function  more()
    {
        if (IS_POST) {
        $model = D("AuthRule");
        if (!$model->create()) { // 登录验证数据     // 验证没有通过 输出错误提示信息

        dump( $model->getError());

        } else {     // 验证通过 执行登录操作

             $result=$model->add();
        if($result)
        {
             $this->success("添加成功",U('lists'));
        }else{
             $this->error('添加失败',U('lists'));
        }
        }

        }else{
        $this->display('add');
        }
    }
    public  function  remove()
    {
        if(IS_POST)
        {
            $id=I("post.");
            $ids=implode(',',$id['ids']);
        }else{
            $ids=I("ids");
        }
        $model=M("AuthRule");
        $result=$model->delete($ids);

        if($result)
        {
            $this->success("success",U('lists'),3);
        }else{
            $this->error("error",U('lists'),3);
        }
    }
    public  function  modify()
    {
        $id=I("id");
        if (IS_POST) {
        $model = D("AuthRule");
        if (!$model->create()) { // 登录验证数据     // 验证没有通过 输出错误提示信息

            dump( $model->getError());

        } else {     // 验证通过 执行登录操作
            $result=$model->save();
        if($result)
        {
            $this->success("更新成功成功",U('lists'));
        }else{
            $this->error('更新失败',U('modify',array('id'=>$id)));
        }
        }

        }else{
            $model = M("AuthRule");
            $list = $model->where(array("id"=>$id))->select();
            $this->assign('list', $list[0]);
            $this->display('modify');
        }
    }
    public function pageShow($count, $pageSize,$search=null)
    {
        $Page = new \Think\Page($count, $pageSize,$search);
        $Page->setConfig('header', ' ');
        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('last', '末页');
        $Page->setConfig('first', '首页');
        $Page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        return $Page->show();
    }
}
